package com.fwtai.api.controller;

import com.fwtai.config.ConfigFile;
import com.fwtai.entity.ReqPage;
import com.fwtai.service.api.ApiGoodsOrderService;
import com.fwtai.tool.ToolClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 微信支付订单控制层|路由层[api]
 * @作者 李宇鹏
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2023-04-11 13:44:32
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@Api(tags = "微信支付订单",description = "token选填")
@RequestMapping(ConfigFile.guest_v10 +"goodsOrder")
public class GoodsOrderController{

  private final ApiGoodsOrderService apiGoodsOrderService;

  public GoodsOrderController(final ApiGoodsOrderService apiGoodsOrderService){
    this.apiGoodsOrderService = apiGoodsOrderService;
  }

  /**添加 -- 已废弃*/
  @ApiOperation(value = "添加微信支付订单", notes = "新建|新增|添加操作,bean实体form表单方式非json格式提交,<span class='danger'>前端需要处理日期时间格式为时间戳</span>")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "user_id", value = "购买人|付费用户id,限制长度19个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "buyer_type", value = "购买类型（1是用户购买；2是直营店向区级购买；3区级向总公司购买）,限制长度1个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "openId", value = "微信的openId,限制长度40个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "transaction_id", value = "交易标识码（交易单号）,限制长度64个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "out_trade_no", value = "订单号,限制长度19个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "total_fee", value = "支付金额,限制长度15个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "status", value = "支付状态(0未支付;1已支付),限制长度1个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "evaluate", value = "评价状态(0待评价;1已评价),限制长度1个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "refund", value = "退款状态(0未退款;1已退款),限制长度1个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "version", value = "版本号(乐观锁),限制长度10个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "body", value = "支付描述（下单描述）,限制长度128个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "pay_date", value = "付款日期（支付成功后更新）,限制长度10个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "add_date", value = "下单时间,限制长度10个", dataType = "int", paramType = "query", required = true),
  })
  @PostMapping("/add")
  public void add(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.add(request),response);
  }

  /**编辑 -- 已废弃*/
  @ApiOperation(value = "编辑微信支付订单", notes = "通过主键kid编辑|修改数据,字段的参照表结构，主键的字段可能不是id或kid,请参考表结构,<span class='danger'>前端需要处理日期时间格式为时间戳</span>")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "kid", value = "被修改的主键值,其余的参照表结构", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "user_id", value = "购买人|付费用户id,限制长度19个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "buyer_type", value = "购买类型（1是用户购买；2是直营店向区级购买；3区级向总公司购买）,限制长度1个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "openId", value = "微信的openId,限制长度40个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "transaction_id", value = "交易标识码（交易单号）,限制长度64个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "out_trade_no", value = "订单号,限制长度19个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "total_fee", value = "支付金额,限制长度15个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "status", value = "支付状态(0未支付;1已支付),限制长度1个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "evaluate", value = "评价状态(0待评价;1已评价),限制长度1个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "refund", value = "退款状态(0未退款;1已退款),限制长度1个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "version", value = "版本号(乐观锁),限制长度10个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "body", value = "支付描述（下单描述）,限制长度128个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "pay_date", value = "付款日期（支付成功后更新）,限制长度10个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "add_date", value = "下单时间,限制长度10个", dataType = "int", paramType = "query", required = true),
  })
  @PostMapping("/edit")
  public void edit(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.edit(request),response);
  }

  /**根据主键kid查询对应的数据*/
  @ApiOperation(value = "获取单条的微信支付订单详细信息", notes = "通过主键kid获取微信支付订单详细信息")
  @ApiImplicitParam(name = "id", value = "被查看的kid", dataType = "String", paramType = "query", required = true)
  @GetMapping("/queryById")
  public void queryById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.queryById(id),response);
  }

  /**获取分页数据,请勿删除ReqPage否则swagger不显示参数*/
  @ApiOperation(value = "获取微信支付订单分页数据,默认仅含数据不含总记录数总条数", notes = "其参数是搜索过滤条件;排序的key为column值为返回的字段，排序关键字的key为order,其值可选正序ASC|倒序DESC<br/>注意调用端需要判断每次请求返回的条数是否小于每页大小或返回的code=201而停止下一次请求<br/><span class='danger'>前端需要处理日期时间格式为时间戳</span>")
  @GetMapping("/listDataPage")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "out_trade_no", value = "订单号", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "status", value = "提货状态(1待确认收货;2已完成;不传则是全部)", dataType = "String", paramType = "query", required = false)
  })
  public void listDataPage(final ReqPage reqPage,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.listData(request),response);
  }

  //消费者展示活动购买订单
  @ApiOperation(value = "消费者展示活动购买订单,默认仅含数据不含总记录数总条数", notes = "其参数是搜索过滤条件;排序的key为column值为返回的字段，排序关键字的key为order,其值可选正序ASC|倒序DESC<br/>注意调用端需要判断每次请求返回的条数是否小于每页大小或返回的code=201而停止下一次请求<br/><span class='danger'>前端需要处理日期时间格式为时间戳</span>")
  @GetMapping("/getPromotionOrder")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "out_trade_no", value = "订单号", dataType = "String", paramType = "query", required = false),
    @ApiImplicitParam(name = "status", value = "提货状态(1待确认收货;2已完成;不传则是全部)", dataType = "String", paramType = "query", required = false)
  })
  public void getPromotionOrder(final ReqPage reqPage,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.listData(request),response);
  }

  /**积分统计 -- 已废弃*/
  @ApiOperation(value = "积分统计", notes = "积分统计")
  @GetMapping("/queryAllIntegral")
  public void queryAllIntegral(final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.queryAllIntegral(),response);
  }

  /**订单统计*/
  @ApiOperation(value = "订单统计", notes = "订单统计")
  @GetMapping("/getAllOrder")
  public void getAllOrder(final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.getAllOrder(),response);
  }

  /**用户（门店、区级代理）的销售订单列表*/
  @ApiOperation(value = "用户（门店、区级代理）的销售订单列表", notes = "用户（门店、区级代理）的销售订单列表,notes是备注")
  @GetMapping("/getIntegralList")
  public void getIntegralList(final ReqPage reqPage,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.getIntegralList(request),response);
  }

  @ApiOperation(value = "我的销售订单增加自定义备注", notes = "我的销售订单增加自定义备注")
  @PostMapping("/addOrderNotes")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "kid", value = "订单id", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "type", value = "自定义备注的类型(1是微信订单,2是积分订单)", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "notes", value = "备注信息", dataType = "String", paramType = "query", required = true)
  })
  public void addOrderNotes(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.addOrderNotes(request),response);
  }

  @ApiOperation(value = "用户确认收货(用户已取货)", notes = "用户确认收货(用户已取货)")
  @PostMapping("/editCargoStatus")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "out_trade_no", value = "订单编号", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "type", value = "订单类型(1是微信支付订单,2是积分进货订单)", dataType = "int", paramType = "query", required = true)
  })
  public void editCargoStatus(final String out_trade_no,final String type,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.editCargoStatus(type,out_trade_no),response);
  }

  //查询积分购买商品的订单列表
  @ApiOperation(value = "查询积分购买商品的订单列表,默认仅含数据不含总记录数总条数,token必填", notes = "查询积分购买商品的订单列表")
  @GetMapping("/listIntegralOrder")
  @ApiImplicitParam(name = "status", value = "提货状态(1待确认收货;2已完成;不传则是全部)", dataType = "String", paramType = "query", required = false)
  public void listIntegralOrder(final ReqPage reqPage,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.listIntegralOrder(request),response);
  }

  //查询积分购买商品的订单详情
  @ApiOperation(value = "查询积分购买商品的订单详情,token必填", notes = "查询积分购买商品的订单详情")
  @ApiImplicitParam(name = "id", value = "被查看的kid", dataType = "long", paramType = "query", required = true)
  @GetMapping("/queryIntegralOrderInfo")
  public void queryIntegralOrderInfo(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.queryIntegralOrderInfo(id),response);
  }

  //我的积分销售订单列表
  @ApiOperation(value = "获取我的积分销售订单列表", notes = "获取我的积分销售订单列表")
  @GetMapping("/getIntegralSalesOrder")
  public void getIntegralSalesOrder(final ReqPage reqPage,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.getIntegralSalesOrder(request),response);
  }

  //按用户id查看销售信息
  @ApiOperation(value = "按用户id查看销售信息,token必填", notes = "按用户id查看销售信息")
  @ApiImplicitParam(name = "id", value = "被查看用户的kid", dataType = "long", paramType = "query", required = true)
  @GetMapping("/queryOrderList")
  public void queryOrderList(final ReqPage reqPage,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.queryOrderList(request),response);
  }

  /**根据商户单号查询对应的数据*/
  @ApiOperation(value = "获取单条的微信支付和积分支付订单详细信息", notes = "通过out_trade_no获取订单详细信息")
  @ApiImplicitParam(name = "out_trade_no", value = "被查看的out_trade_no", dataType = "String", paramType = "query", required = true)
  @GetMapping("/queryIncomeDetails")
  public void queryIncomeDetails(final Long out_trade_no,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.queryIncomeDetails(out_trade_no),response);
  }

  /**返回门店或区代微信支付和积分支付订单列表*/
  @ApiOperation(value = "获取门店或区代微信支付和积分支付订单列表", notes = "获取门店或区代微信支付和积分支付订单列表")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "userId", value = "被查看的用户", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "storeId", value = "被查看的门店id,查询门店时必传", dataType = "String", paramType = "query", required = false)
  })
  @GetMapping("/queryAllOrderList")
  public void queryAllOrderList(final ReqPage reqPage,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.queryAllOrderList(request),response);
  }

  @ApiOperation(value = "查询订单发货状态,token必填", notes = "查询订单发货状态")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "transaction_id", value = "某个门店的子订单号",dataType ="String", paramType = "query", required = true)
  })
  @GetMapping("/getTransactionTrade")
  public void getTransactionTrade(final String transaction_id,final HttpServletResponse response){
    ToolClient.responseJson(apiGoodsOrderService.getTransactionTrade(transaction_id),response);
  }
}